#coding=utf-8
import unittest
from appium import webdriver
from selenium import webdriver
from time import sleep
from selenium.common.exceptions import WebDriverException


#导航栏相关的参数
work_address = "//android.widget.LinearLayout[@resource-id='cn.com.egova.egovamobile:id/base_tab_tabs_bottom']/android.widget.LinearLayout[2]/android.widget.FrameLayout[1]/android.widget.RadioButton[1]"
connecter_address = "//android.widget.LinearLayout[@resource-id='cn.com.egova.egovamobile:id/base_tab_tabs_bottom']/android.widget.LinearLayout[3]/android.widget.FrameLayout[1]/android.widget.RadioButton[1]"
owner_address = "//android.widget.LinearLayout[@resource-id='cn.com.egova.egovamobile:id/base_tab_tabs_bottom']/android.widget.LinearLayout[4]/android.widget.FrameLayout[1]/android.widget.RadioButton[1]"
message_address = "//android.widget.LinearLayout[@resource-id='cn.com.egova.egovamobile:id/base_tab_tabs_bottom']/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RadioButton[1]"
work = "工作"
connecter = "联系人"
owner = "我的"
message = "消息"


class nav_plugin_factory():

    #导航栏操作：包含：消息、工作、联系人、我的，根据传入的 type类型，确认为点击哪个导航
    def nav_open(self,type,driver):
        if work.decode("utf-8")in type:
            driver.find_element_by_xpath(work_address).click()
            print "工作TAB页正常打开"
            sleep(2)
        elif connecter.decode("utf-8")in type:
            driver.find_element_by_xpath(connecter_address).click()
            print "联系人TAB页正常打开"
            sleep(2)
        elif owner.decode("utf-8")in type:
            driver.find_element_by_xpath(owner_address).click()
            print "我的TAB页正常打开"
            sleep(2)
        elif message.decode("utf-8")in type:
            driver.find_element_by_xpath(message_address).click()
            print "消息TAB页正常打开"
            sleep(2)
        else:
            print "传入的导航栏参数错误"
        return  True

    # 插件操作操作：根据传入的插件名称，进行定位并打开
    def plugin_open(self,plugin_name,driver):
        try:
            driver.find_element_by_name(plugin_name).click()
            print plugin_name + "..插件已经正常打开...".decode("utf-8")
            print "..插件已经正常打开..."
        #print plugin_name.decode("utf-8") + "..插件已经正常打开..."
        except WebDriverException,el_error:
            print el_error


if __name__ == '__main__':
    unittest.main()
